const jwt = require("jsonwebtoken");
const { dbName, http } = require("../modal/db.config");
const SECRET = dbName;
const { getCurrentDateTime } = require("../modal/time.config");

// 实现数据的可视化展示，比如用户注册量，根据注册用户的性别分析该系统的用户占比
exports.getSexCompare = async (req, res) => {
  const body = req.body;
  let userList = await req.services.UserService.findAll();
  const man=userList.filter(item=>item.sex===1);
  const woman=userList.filter(item=>item.sex===0);
  res.status(200).json({
    data: {
      total: userList.length,
      man: man.length,
      woman: woman.length,
    },
    msg: "success",
    code: 200,
  });
};

//根据用户加入的课程以及观看视频的进度分析该系统内课程的接受度
exports.getVideoLove = async (req, res) => {
  const body = req.body;
  let list = await req.services.CourseService.findAllHistory();
  let course = await req.services.CourseService.findAll();

  course.map(item=>{
    item.love=list.filter(item2=>item2.course_id===item.id).length;
  })

  res.status(200).json({
    data: course,
    msg: "success",
    code: 200,
  });
};


// 根据发布的问卷数量的填写情况分析系统应该几天发布问卷比较好

exports.getQuestionnaireAnalysis = async (req, res) => {
  const body = req.body;
  let records = await req.services.QuestionnaireService.getRecordAll();
  let list = await req.services.QuestionnaireService.findAll();
  list.map(item=>{
    item.love=records.filter(item2=>Number(item2.questionnaireId)===Number(item.id)).length;
  })

  res.status(200).json({
    data: list,
    msg: "success",
    code: 200,
  });
};
